import Axios from 'axios'
import testApi from './TestApi'

const http = Axios.create({})
// 请求拦截器，可配置多个，按配置的顺序在请求发送前执行
http.interceptors.request.use(function (config) {
  // 
  config.headers['Authorization'] = `Bearer ${sessionStorage.getItem('token')}`
  return config
})
// 响应拦截器， 对返回的结果进行统一判断
http.interceptors.response.use(function (res) {
  return Promise.resolve(res.data)
}, function (err) {
  return Promise.reject(err)
})

const backendUrl = `${process.env.VUE_APP_BACKEND}/backend`

const testApi = new TestApi(http, backendUrl)
export {
  testApi
}
